var path = require("path");
var webpack = require("webpack");
var htmlWebpackPlugin = require("html-webpack-plugin");
var commonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin");
var copyWebpackPlugin = require("copy-webpack-plugin");
const cleanWebpackPlugin = require('clean-webpack-plugin');
const extractTextPlugin = require('extract-text-webpack-plugin');

module.exports={
	entry: {
		jquery: ['jquery'],
		app: './src/app.js',
		vendor: ['angular','@uirouter/angularjs','oclazyload'],
	},
	output: {
		filename: '[name].[hash:8].js',
		path: path.resolve(__dirname,"dist")
	},
	devServer: {
		contentBase: "./dist",
		port: 8090,
		hot: true
	},
	module: {
		rules: [
			{
				test: /\.css$/,
				use: extractTextPlugin.extract({
					fallback: "style-loader",
					use: "css-loader"
				})
			},
			{
				test: /\.(png|jpg|gif)$/,
				use: [
					{
						loader: 'file-loader',
						options: {
							name: '[name].[hash:8].[ext]',
						}
					}
				]
			}
		]
	},
	plugins: [
		new cleanWebpackPlugin(['dist']),
		new htmlWebpackPlugin({
			filename: 'index.html',
			template: './src/index.html',
			title: 'angular-webpack-demo'
		}),
		new webpack.optimize.CommonsChunkPlugin({
            names: ['vendor', 'manifest'],
        }),
        new webpack.HotModuleReplacementPlugin(),
        new copyWebpackPlugin([
        	{
        		from: './src/assets', to: './assets'
        	}
        ]),
        new extractTextPlugin("[name].css")
	]
};